package com.itcast.yygh.hosp.controller;

import com.itcast.common.result.R;
import com.itcast.yygh.hosp.service.DepartmentService;
import com.itcast.yygh.hosp.service.HospitalService;
import com.itcast.yygh.hosp.service.ScheduleService;
import com.itcast.yygh.model.model.hosp.Hospital;
import com.itcast.yygh.model.model.hosp.Schedule;
import com.itcast.yygh.model.vo.hosp.DepartmentVo;
import com.itcast.yygh.model.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 医疗-用户系统首页医疗数据
 */
@Api(tags = "预约平台医院数据")
@RestController
@RequestMapping("/api/hosp/hospital")
@RequiredArgsConstructor
public class HospitalApiController {
    //引入service依赖
    private final HospitalService hospitalService;
    private final DepartmentService departmentService;
    private final ScheduleService scheduleService;

    // 医院数据分页查询
    @ApiOperation("分页查询医院数据")
    @GetMapping("/findPage/{page}/{limit}")
    public R findPage(@PathVariable Integer page,
                      @PathVariable Integer limit,
                      HospitalQueryVo queryVo) {
        // 调用service查询分页数据
        Page<Hospital> pages = hospitalService.findPage(page, limit, queryVo);
        // 返回对应结果集
        return R.ok().data("pages", pages);
    }

    //根据医院名称获取医院列表数据
    @ApiOperation("根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public R findByHosname(
            @ApiParam(name = "hosname", value = "医院名称", required = true)
            @PathVariable String hosname) {

        List<Hospital> list = hospitalService.findByHosname(hosname);
        return R.ok().data("list",list);
    }

    //查询医院对应的科室列表
    @ApiOperation("获取科室列表")
    @GetMapping("/findDepart/{hoscode}")
    public R findDepart(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {

        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return R.ok().data("list",list);
    }

    //查询医院的详情数据
    @ApiOperation("医院预约挂号详情")
    @GetMapping("/findHospDetail/{hoscode}")
    public R findHospDetail(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {

        Map<String, Object> map = hospitalService.findHospDetail(hoscode);
        return R.ok().data(map);
    }

    @ApiOperation("获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {

        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    @ApiOperation("获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }

    @ApiOperation("获取排班详情")
    @GetMapping("getSchedule/{id}")
    public R getScheduleList(
            @PathVariable String id) {
        Schedule schedule = scheduleService.getById(id);
        return R.ok().data("schedule",schedule);
    }
}
